package com.ouyy.volunteerservice.volunteer.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ouyy.volunteerservice.volunteer.domain.po.Volunteers;
import com.ouyy.volunteerservice.volunteer.mapper.VolunteersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class VolunteersService {
    @Autowired
    private VolunteersMapper volunteersMapper;

    public Volunteers findByUsernameAndPassword(String username, String password,int isAdmin) {
        return volunteersMapper.selectOne(new QueryWrapper<Volunteers>().eq("name", username).eq("password", password).eq("is_admin",isAdmin));
    }

    public boolean findByUsername(String username) {
        if (volunteersMapper.selectOne(new QueryWrapper<Volunteers>().eq("name", username).eq("is_admin",1)) != null){
            return true;
        }
        return false;
    }

    public boolean insert(Volunteers volunteers) {
        try {
            volunteersMapper.insert(volunteers);
            return true;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
